package com.ruoyi.system.service.impl;

import com.ruoyi.system.entity.PersonnelArchives;
import com.ruoyi.system.mapper.PersonnelArchivesMapper;
import com.ruoyi.system.service.PersonnelArchivesService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 人员档案(PersonnelArchives)表服务实现类
 *
 * @author makejava
 * @since 2022-11-22 09:00:34
 */
@Service("personnelArchivesService")
public class PersonnelArchivesServiceImpl implements PersonnelArchivesService {
    @Resource
    private PersonnelArchivesMapper personnelArchivesDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PersonnelArchives queryById(Integer id) {
        return this.personnelArchivesDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param personnelArchives 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<PersonnelArchives> queryByPage(PersonnelArchives personnelArchives, PageRequest pageRequest) {
        long total = this.personnelArchivesDao.count(personnelArchives);
        return new PageImpl<>(this.personnelArchivesDao.queryAllByLimit(personnelArchives, pageRequest), pageRequest, total);
    }

    @Override
    public List<PersonnelArchives> selectList(PersonnelArchives personnelArchives) {
        return personnelArchivesDao.queryAll(personnelArchives);
    }

    /**
     * 新增数据
     *
     * @param personnelArchives 实例对象
     * @return 实例对象
     */
    @Override
    public PersonnelArchives insert(PersonnelArchives personnelArchives) {
        this.personnelArchivesDao.insert(personnelArchives);
        return personnelArchives;
    }

    /**
     * 修改数据
     *
     * @param personnelArchives 实例对象
     * @return 实例对象
     */
    @Override
    public PersonnelArchives update(PersonnelArchives personnelArchives) {
        this.personnelArchivesDao.update(personnelArchives);
        return this.queryById(personnelArchives.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.personnelArchivesDao.deleteById(id) > 0;
    }
}
